﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CatUtils.Utils.SpecialUtils.PicBed.Sougou
{
    public class SougouPicBed
    {
        /// <summary>
        /// 上传图片链接
        /// </summary>
        /// <param name="ImgUrl"></param>
        /// <returns></returns>
        public static string ImgLink(string ImgUrl)
        {
            string TempFile = WebHelper.DownloadToFile(ImgUrl, FileNameHelper.CreateFileNameWithExtension(FileNameHelper.CreateTempFileName(), ".jpg"));

            string TempImgLink = SingleFile(TempFile);
            FileHelper.FileDelete(TempFile);
            return TempImgLink;
        }

        /// <summary>
        /// 上传单个文件
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public static string SingleFile(string FilePath)
        {
            if (FilePath == "")
                return "";
            string WebLink = WebHelper.UploadFile("http://pic.sogou.com/pic/upload_pic.jsp", FilePath,
                WebHelper.PcWebHeader(true));
            if (WebLink.Length > 10)
                return WebLink;
            return "";
        }
    }
}